﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace WebBanThuoc.Server
{
    public class ServerWeb : WebBanThuoc.Server.IServerWeb
    {
        private SqlConnection connection;

        public SqlConnection Connection
        {
            get { return connection; }            
        }
        public ServerWeb()
        {
            getConnection();
        }
        public ServerWeb(string serverName)
        {
            getConnection(serverName);
        }
        private void getConnection(string serverName)
        {
            string strCon = System.Configuration.ConfigurationManager.ConnectionStrings[serverName].ConnectionString;
            connection = new SqlConnection(strCon);            
        }

        private void getConnection()
        {
            string strCon = System.Configuration.ConfigurationManager.ConnectionStrings["defaultServer"].ConnectionString;
            connection = new SqlConnection(strCon);
        }

        public void closeConnection()
        {
            try
            {
                if (this.connection != null)
                {
                    if (this.connection.State != ConnectionState.Closed)
                    {
                        this.connection.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}